package db.tables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import com.db.Table;

import db.beans.T_WebsiteCategoryBean;

public class T_WebsiteCategoryTable extends Table{

	public static final String TABLE_NAME = "T_WEBSITE_CATEGORY";
	public static final String COL_WEBSITE_ID = "WEBSITE_ID";
	public static final String COL_WEBSITE_CATEGORY_ID = "WEBSITE_CATEGORY_ID";
	public static final String COL_WEBSITE_CATEGORY_NAME = "WEBSITE_CATEGORY_NAME";
	public static final String COL_WEBSITE_BELONG_CATEGORY_ID = "WEBSITE_BELONG_CATEGORY_ID ";
	public static final String COL_CATEGORY_ID = "CATEGORY_ID";
	public static final String COL_DELETE_FLAG = "DELETE_FLAG";


	public static T_WebsiteCategoryBean[] selectAll(Connection conn) throws SQLException {
		final String sql = "SELECT "
				+ COL_WEBSITE_ID + ","
				+ COL_WEBSITE_CATEGORY_ID + ","
				+ COL_WEBSITE_CATEGORY_NAME + ","
				+ COL_WEBSITE_BELONG_CATEGORY_ID + ","
				+ COL_CATEGORY_ID + ","
				+ COL_DELETE_FLAG
				+ " FROM " + TABLE_NAME;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		Vector<T_WebsiteCategoryBean> v = new Vector<T_WebsiteCategoryBean>();
		try {
			stmt = conn.prepareStatement(sql);
			rs = stmt.executeQuery();
			int i;
			while (rs.next()) {
				i = 0;
				T_WebsiteCategoryBean rec = new T_WebsiteCategoryBean();
				rec.setWebsiteId(rs.getInt(++i));
				rec.setWebsiteCategoryId(rs.getInt(++i));
				rec.setWebsiteCategoryName(rs.getString(++i));
				rec.setWebsiteBelongCategoryId(rs.getInt(++i));
				rec.setCategoryId(rs.getInt(++i));
				rec.setDeleteFlag(rs.getInt(++i) == NOT_DELETE_FLAG);
				v.add(rec);
			}
		} finally {
			if (rs != null) {
				rs.close();
			}

			if (stmt != null) {
				stmt.close();
			}
		}
		return (T_WebsiteCategoryBean[]) v.toArray(new T_WebsiteCategoryBean[v.size()]);
	}
}
